#include "junix.h"

ssize_t jreadn(int fd, char *buf, size_t sz)
{
	size_t left=sz,len;
	char *p=buf;

	if(buf==NULL)
		err_quit("buf is NULL");

	while( (len=Read(fd,p,left))>0)
	{
		p += len;
		left -= len;
		if( !left )
			break;
	}

	return  (sz-left);
}

int main(int argc, char **argv)
{
	char buf[100];
	int fd=Open("XXX", O_RDONLY);
	int len=jreadn( fd,buf,40);
	printf("Read %d byte\n\n",len);
	Write(STDOUT_FILENO, buf, len);
	printf("\n",len);

	exit(0);
}

